from transformers import pipeline

# 运行该段代码要保障你的电脑能够上网，会自动下载预训练模型，大概420M
# 这里引入了一个任务叫fill-mask，该任务使用了base的bert模型
unmasker = pipeline("fill-mask", model="bert-base-uncased")
# 输出mask的指，对应排名最前面的5个，也可以设置其他数字
a = unmasker("The goal of life is [MASK].", top_k=5)
# print(a)


''' 输出结果如下，似乎都不怎么有效哈。
[{'score': 0.10933303833007812,
  'token': 2166,
  'token_str': 'life',
  'sequence': 'the goal of life is life.'},
 {'score': 0.03941883146762848,
  'token': 7691,
  'token_str': 'survival',
  'sequence': 'the goal of life is survival.'},
 {'score': 0.032930608838796616,
  'token': 2293,
  'token_str': 'love',
  'sequence': 'the goal of life is love.'},
 {'score': 0.030096106231212616,
  'token': 4071,
  'token_str': 'freedom',
  'sequence': 'the goal of life is freedom.'},
 {'score': 0.024967126548290253,
  'token': 17839,
  'token_str': 'simplicity',
  'sequence': 'the goal of life is simplicity.'}]
'''
